home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Database / SimpleTableView-1 / DataTable.h < prev    next >
Text File  |  1995-06-12  |  4KB  |  131 lines

  1. // -------------------------------------------------------------------------------------
  2. //  DataTable
  3. //  This software is without warranty of any kind.  Use at your own risk.
  4. // -------------------------------------------------------------------------------------
  5.  
  6. #import <objc/Object.h>
  7.  
  8. // -------------------------------------------------------------------------------------
  9. // column data types
  10. #define CDT_TYPES            "?SBI"
  11. #define    CDT_UNKNOWN            0
  12. #define    CDT_STRING            1
  13. #define    CDT_BOOLEAN            2
  14. #define    CDT_INTEGER            3
  15.  
  16. // -------------------------------------------------------------------------------------
  17. // column definition
  18. #define    DATATYPE_UNDEFINED    0
  19. typedef struct {
  20.     int                        index;            // physical ordering (0 == key)
  21.     char                    *keyTag;        // lookup key name buffer
  22.     char                    *title;            // column title
  23.     char                    type;            // data type
  24.     NXCoord                    size;            // width of column
  25.     NXCoord                    minSize;        // minimum size of column
  26.     int                        displayOrder;    // displayed ordering
  27.     int                        alignment;        // column content alignment
  28.     BOOL                    isEditable;        // content editability
  29.     BOOL                    isHidden;        // don't show column
  30.     char                    *nilValue;        // value equivalent to "empty"
  31. } dataColumn_t;
  32.  
  33. // -------------------------------------------------------------------------------------
  34. // table definition
  35. typedef struct {
  36.     char                    *name;
  37.     char                    *access;
  38.     NXSize                    viewSize;
  39.     time_t                    date;
  40.     id                        columnId;
  41.     id                        reorderId;
  42.     id                        dataId;
  43. } dataTable_t;
  44.  
  45. // -------------------------------------------------------------------------------------
  46. // row:colmn entry
  47. typedef struct {
  48.     char                    *value;
  49.     int                        isValid;    /* -1, 0, 1 */
  50. } dataEntry_t;
  51.  
  52. #define entryNEW                ((dataEntry_t*)malloc(sizeof(dataEntry_t)))
  53. #define entryPTR(R,C)            ((R)?(dataEntry_t*)[(R) objectAt:(C)]:(dataEntry_t*)nil)
  54. #define entryVALUE(R,C)            (entryPTR(R,C)->value)
  55. #define entryVALID(R,C)            (entryPTR(R,C)->isValid)
  56.  
  57. // -------------------------------------------------------------------------------------
  58. @interface DataTable : Object
  59. {
  60.  
  61.     id                        delegate;
  62.     
  63.     id                        nullIndex;
  64.     BOOL                    isModified;
  65.  
  66.     dataTable_t                *tableHandle;
  67.     
  68. }
  69.  
  70. // -------------------------------------------------------------------------------------
  71.  
  72. - initFromFile:(const char*)fileName;
  73. - free;
  74.  
  75. - setDelegate:aDelegate;
  76. - delegate;
  77. - setNullIndex:index;
  78. - setViewSize:(NXSize*)size;
  79. - (const NXSize*)viewSize;
  80.  
  81. - (BOOL)tableHasChanged;
  82. - setDocEdited:(BOOL)flag;
  83. - commitTable;
  84.  
  85. - newRowName:(const char*)rowN copyFromRow:(int)rowX;
  86. - deleteRowAt:(int)rowX;
  87.  
  88. - (int)sortCompare:(dataColumn_t*)dc values:(const char*)val1:(const char*)val2;
  89. - sortTableByColumn:(int)pri :(int)sec;
  90. - sortTableByColumnName:(const char*)priName :(const char*)secName;
  91.  
  92. + (dataColumn_t*)_column:infoId infoAt:(int)n;
  93. - (dataColumn_t*)columnInfoAt:(u_int)col;
  94. - (const char*)copyStringValue:(const char*)value forColumn:(int)index;
  95. - (dataColumn_t*)orderedColumnInfoAt:(u_int)ord;
  96. - addColumnInfo:(dataColumn_t*)dc;
  97. - setDisplayOrder:(int)order andWidth:(float)width forColumnIndex:(int)column;
  98.  
  99. - (const char*)tableName;
  100. - (const char*)tableTitle;
  101. - (const char*)tableAccess;
  102. - (u_int)actualColumnCount;
  103. - (u_int)visibleColumnCount;
  104. - (u_int)columnCount;
  105. - (u_int)rowCount;
  106.  
  107. - (BOOL)hasVerificationErrors;
  108. - (BOOL)verifyValueAt:(u_int)row :(u_int)column;
  109. - (BOOL)verifyValue:(const char*)value dataType:(int)dataType;
  110.  
  111. - (int)indexForColumnName:(const char*)name;
  112. - (int)indexForRowName:(const char*)rowN exactMatch:(BOOL)exact;
  113. - (dataEntry_t*)entryAtIndex:(u_int)rowX :(u_int)colX;
  114. - (const char*)valueForRowName:(const char*)rowN columnName:(const char*)colN;
  115. - (const char*)valueAtIndex:(u_int)rowX :(u_int)colX;
  116. - (const char*)valueFor:(u_int)rowIndex :(u_int)columnIndex;
  117. - setValue:(const char*)value atIndex:(u_int)rowX :(u_int)colX;
  118. - setValue:(const char*)value forRowName:(const char*)rowN columnName:(const char*)colN;
  119. - setValueFor:rowIndex :colIndex from:aValue;
  120. - setValueFor:colIndex at:(u_int)rowPosition from:aValue;
  121. - getValueFor:rowIndex :columnIndex into:aValue;
  122. - getValueFor:index at:(u_int)aPosition into:aValue;
  123. - (int)scanForValue:(const char*)value inColumnName:(const char*)colN
  124.     startingAtRow:(int)rowX backwards:(BOOL)back;
  125.  
  126. - (time_t)timestamp;
  127. - readTableColumns;
  128. - readTableData;
  129. - writeTable;
  130.  
  131. @end